<%--
  @author Duminda Dharmakeerthi
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/dateSelector.js"></script>
<script src="${pageContext.request.contextPath}/js/landRegistration/landGrants.js" type="text/javascript"></script>
<script src="${pageContext.request.contextPath}/js/minSubDivisionUnitConvertor.js" type="text/javascript"></script>
<script type="text/javascript">

    $(document).ready(function () {
        validateLandGrantDetails();

    });

    function validateLandGrantDetails() {
        $('#issueDate').rules("add", {
            isDateFormated:true,
            isFeatureDate:true,
            messages:{
                ageValidate:$('#pls_enter_valid_age').val()}
        });

        $('#folioDate').rules("add", {
            isDateFormated:true,
            isFeatureDate:true,
            messages:{
                ageValidate:$('#pls_enter_valid_age').val()}
        });
        $('#startedDate').rules("add", {
            isDateFormated:true,
            isFeatureDate:true,
            messages:{
                ageValidate:$('#pls_enter_valid_age').val()}
        });
    }


    function initialValidate() {
        initialGrants();
    }
    function detailValidate() {
        //        alert("detail");
    }
    function showViolationComment() {
        $('#violationComment').show();
    }

    function hideViolationComment() {
        $('#violationComment').hide();
        $('#conditionsViolationComment').val('');
    }

    function violationCommentClick() {
        if ($('#conditionsViolatedOrNot0').is(':checked')) {
            hideViolationComment();
        } else {
            showViolationComment();
        }
    }

</script>
<script type="text/javascript">
    function disableFields() {
        var fields = new Array(
                'referenceNo',
                'issueDate',
                'folioNo',
                'folioDate',
                'folioLocation',
                'developmentState',
                'alienationComment',
                'conditionsViolatedOrNot0',
                'conditionsViolatedOrNot1',
                'conditionsViolationComment',
                'minHectareId',
                'minAcreId',
                'minRoodsId',
                'minPerchesId',
                'minFraction',
                'nameOfBank',
                'addressOfBank',
                'startedDate',
                'mortgagePeriodInYears',
                'mortgagePeriodInMonths',
                'conditions'
                );
        enableFields(fields);
    }

    $(function () {
        disableFields();
        if ($('#landMode').val() == 'DETAIL') {
            violationCommentClick();
        } else {
            hideViolationComment();
        }
        disablePaste(new Array(
                'minFraction',
                'minHectareId',
                'minAcreId',
                'minRoodsId',
                'minPerchesId'
                ));
    });

    $('#minHectareId').change(function () {
        $('#minHectareId').val(parseFloat(($('#minHectareId').val().length == 0) ? 0 : $('#minHectareId').val()));
        changeMinHectare();
    });
</script>

    <h3><s:label value="%{getText('land_grants_details.label')}"/> </h3>
    <fieldset>
    <div id="land-grants-details">
        <table class="width-100">
            <tr>
                <td><s:label value="%{getText('grant_no.label')}"/></td>
                <td><s:textfield id="referenceNo" name="alienation.referenceNo" cssClass="width-200-px"/></td>
                <td><s:label value="%{getText('date_of_approved.label')}"/> <s:label
                        value="%{getText('date_format.label')}" cssClass="date-format"/></td>
                <td><s:textfield id="issueDate" name="alienation.issueDate" onclick="selectDate('issueDate')"
                                 cssClass="width-200-px" onKeyPress="return dateNumbersOnly(event,true)"/></td>
            </tr>
            <tr>
                <td><s:label value="%{getText('folio_no.label')}"/></td>
                <td><s:textfield id="folioNo" name="alienation.folioNumber" cssClass="width-200-px"/></td>
                <td><s:label value="%{getText('folio_date.label')}"/> <s:label value="%{getText('date_format.label')}"
                                                                               cssClass="date-format"/></td>
                <td><s:textfield id="folioDate" name="alienation.folioDate" onclick="selectDate('folioDate')"
                                 cssClass="width-200-px" onKeyPress="return dateNumbersOnly(event,true)"/></td>
            </tr>
            <tr>
                <td><s:label value="%{getText('folio_location.label')}"/></td>
                <td colspan="3"><s:textarea id="folioLocation" name="alienation.folioLocation"
                                            cssClass="width-595-px" rows="1"/></td>
            </tr>
            <tr>
                <td><s:label value="%{getText('developed_status.label')}"/></td>
                <td colspan="3" class="left-align"><s:textarea id="developmentState"
                                                               name="alienation.developmentState"
                                                               cssClass="width-595-px" rows="1"/></td>
            </tr>

            <tr>
                <td><s:label value="%{getText('minimum_sub_division_unit.label')}"/></td>
                <td colspan="3">
                    <table class="width-100">
                        <tr>
                            <td><s:label value="%{getText('hectare.label')}"/></td>
                            <td colspan="5"><s:textfield id="minHectareId" name="minHectare"
                                                         cssStyle="width: 80px;"
                                                         onKeyPress="return numbersonly(event,true)"/></td>
                        </tr>
                        <tr>
                            <td><s:label value="%{getText('acre.label')}"/></td>
                            <td><s:textfield id="minAcreId" name="minAcre" cssStyle="width: 80px;"
                                             onKeyPress="return numbersonly(event,true)"/></td>
                            <td><s:label value="%{getText('roods.label')}"/></td>
                            <td><s:textfield id="minRoodsId" name="minRoods" cssStyle="width: 80px;"
                                             onKeyPress="return numbersonly(event,true)"/></td>
                            <td><s:label value="%{getText('perches.label')}"/></td>
                            <td><s:textfield id="minPerchesId" name="minPerches" cssStyle="width: 80px;"
                                             onKeyPress="return numbersonly(event,true)"/></td>
                        </tr>
                    </table>
                </td>
            </tr>
            <tr>
                <td><s:label value="%{getText('minimum_fraction.label')}"/></td>
                <td colspan="3"><s:textfield id="minFraction" name="land.minimumFraction" cssStyle="width: 80px;"
                                             onKeyPress="return numbersonly(event,true)"/></td>
            </tr>
            <%--<tr>
                <td><s:label value="%{getText('comment_about_alienation.label')}"/></td>
                <td colspan="3"><s:textarea id="alienationComment" name="alienation.alienationComment"
                                            cssClass="width-595-px" rows="1"/></td>
            </tr> --%>
            <tr>
                <td><s:label value="%{getText('conditionsViolatedOrNot.label')}"/></td>
                <td colspan="2"><s:radio id="conditionsViolatedOrNot" name="alienation.conditionsViolatedOrNot"
                                         list="#@java.util.HashMap@{'1':getText('yes.label'),'0':getText('no.label')}"
                                         onclick="violationCommentClick()"/></td>
            </tr>
            <tr id="violationComment">
                <td><s:label value="%{getText('conditionsViolationComment.label')}"/></td>
                <td colspan="3"><s:textarea id="conditionsViolationComment" name="alienation.conditionsViolationComment"
                                            rows="1"
                                            cssClass="width-595-px"/></td>
            </tr>
        </table>
    </div>
    </fieldset>

    <h3><s:label value="%{getText('mortgage_details.label')}"/></h3>
    <fieldset>
    <div id="mortgage-details">
        <table class="width-100">
            <tr>
                <td><s:label value="%{getText('name_of_bank_institute.label')}"/></td>
                <td colspan="3"><s:textarea id="nameOfBank" name="alienation.mortgage.nameOfBank"
                                            cssClass="width-595-px" rows="1"/></td>
            </tr>
            <tr>
                <td><s:label value="%{getText('address_of_bank_institute.label')}"/></td>
                <td colspan="3"><s:textarea id="addressOfBank" name="alienation.mortgage.addressOfBank"
                                            cssClass="width-595-px" rows="1"/></td>
            </tr>
            <tr>
                <td><s:label value="%{getText('mortgage_date.label')}"/> <s:label
                        value="%{getText('date_format.label')}" cssClass="date-format"/></td>
                <td colspan="3"><s:textfield id="startedDate" name="alienation.mortgage.startedDate"
                                             onclick="selectDate('startedDate')" cssClass="width-200-px"
                                             onKeyPress="return dateNumbersOnly(event,true)"/></td>
            </tr>
            <tr>
                <td><s:label value="%{getText('mortgage_period.label')}"/></td>
                <td><s:label value="%{getText('years.label')}"/> <s:textfield id="mortgagePeriodInYears"
                                                                              name="alienation.mortgage.mortgagePeriodInYears"
                                                                              cssStyle="width: 80px"
                                                                              onKeyPress="return dateNumbersOnly(event,true)"/></td>
                <td><s:label value="%{getText('months.label')}"/> <s:textfield id="mortgagePeriodInMonths"
                                                                               name="alienation.mortgage.mortgagePeriodInMonths"
                                                                               cssStyle="width: 80px"
                                                                               onKeyPress="return dateNumbersOnly(event,true)"/></td>
                <td></td>
            </tr>
            <tr>
                <td><s:label value="%{getText('mortgage_conditions.label')}"/></td>
                <td colspan="3"><s:textarea id="conditions" name="alienation.mortgage.conditions"
                                            cssClass="width-595-px" rows="1"/></td>
            </tr>
        </table>
    </div>
    </fieldset>

    <h3><s:label value="%{getText('holder_details.label')}"/></h3>
    <fieldset>
    <div id="personal-details">
        <table class="width-100">
            <s:include value="personalDetailsPrintReport.jsp"/>
        </table>
    </div>
    </fieldset>

    <h3><s:label value="%{getText('occupier_details.label')}"/></h3>
    <fieldset>
    <div id="occupier-details">
        <table class="width-100">
            <s:include value="encroacherDetailsPrintReport.jsp"/>
        </table>
    </div>
    </fieldset>

<s:hidden name="alienation.id"/>
<s:hidden name="alienation.holder.id"/>
<s:hidden name="alienation.holder.contacts.id"/>
<s:hidden name="alienation.mortgage.id"/>
<s:hidden name="alienation.holder.holderType" value="1"/>
<s:hidden id="minimumSubDivisionUnit" name="land.minimumSubDivisionUnit"/>


<s:hidden id="pls_enter_reference_no" value="%{getText('pls_enter_reference_no')}"/>
<s:hidden id="pls_enter_name_of_the_land" value="%{getText('pls_enter_name_of_the_land')}"/>
<s:hidden id="pls_enter_plan_no" value="%{getText('pls_enter_plan_no')}"/>
<s:hidden id="pls_enter_lot_no" value="%{getText('pls_enter_lot_no')}"/>
<s:hidden id="pls_enter_valid_no" value="%{getText('pls_enter_valid_no')}"/>
<s:hidden id="pls_select_gn_division" value="%{getText('pls_select_gn_division')}"/>